package com.ylbh.modules.eggupgrade.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ylbh.common.utils.PageDTO;
import com.ylbh.modules.shoppingegg.mapper.ShoppingEggMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ylbh.common.utils.PageUtils;

import com.ylbh.modules.eggupgrade.mapper.ShoppingEggUpgradeSettingMapper;
import com.ylbh.modules.eggupgrade.entity.ShoppingEggUpgradeSetting;
import com.ylbh.modules.eggupgrade.service.ShoppingEggUpgradeSettingService;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Service("shoppingEggUpgradeSettingService")
@Transactional
public class ShoppingEggUpgradeSettingServiceImpl extends ServiceImpl<ShoppingEggUpgradeSettingMapper, ShoppingEggUpgradeSetting> implements ShoppingEggUpgradeSettingService {

    @Autowired
    private ShoppingEggUpgradeSettingMapper shoppingEggUpgradeSettingMapper;

    @Autowired
    private ShoppingEggMapper shoppingEggMapper;

    /**
     * 彩蛋邀请升级配置信息列表
     * @param pageDTO
     * @return
     */
    @Override
    public PageUtils queryEggUpgradeList(PageDTO pageDTO) {
        Page<Integer> page = new Page<>(pageDTO.getPage(), pageDTO.getLimit());
        List<ShoppingEggUpgradeSetting> list = shoppingEggUpgradeSettingMapper.selectEggUpgradeList(pageDTO.getKeywords(), page);
        return new PageUtils(new Page<ShoppingEggUpgradeSetting>().setTotal(page.getTotal()).setRecords(list));
    }

    /**
     * 删除彩蛋邀请升级配置信息
     * @param ids
     */
    @Override
    public void removeEggUpgradeByIds(List<String> ids) {
        shoppingEggUpgradeSettingMapper.updateEggUpgradeDeleteStatusByIds(ids);
        for (String id : ids) {
            shoppingEggMapper.updateJumpUrlLike(id);
        }
    }

    /**
     * 彩蛋邀请升级配置开启状态
     * @param id
     * @param state
     */
    @Override
    public void modifyEggUpgradeStateById(String id, Integer state) {
        ShoppingEggUpgradeSetting entity = new ShoppingEggUpgradeSetting();
        entity.setId(id);
        entity.setState(state);
        shoppingEggUpgradeSettingMapper.updateById(entity);
    }

    /**
     * 新增彩蛋邀请升级配置信息
     * @param shoppingEggUpgradeSetting
     */
    @Override
    public void addEggUpgrade(ShoppingEggUpgradeSetting shoppingEggUpgradeSetting) {
        shoppingEggUpgradeSettingMapper.insertEggUpgrade(shoppingEggUpgradeSetting);
    }
}
